import service from "./index.js";
import qs from "qs";

const cartApi = {
    insert(goodsId) {
        return service.post(`/cart/${goodsId}`);
    },
    delete(id) {
        return service.delete(`/cart/${id}`);
    },
    update(cart) {
        return service.put("/cart",cart);
    },
    selectCartList(){
        return service.get("/cart");
    },
    selectById(id){
        return service.get(`/cart/${id}`);
    },
    //清空所有
    clearCart(){
        return service.delete("/cart/userId");
    },
    //批量删除
    deleteByIds(ids){
        return service.delete("/cart",{
            data:{
                ids
            }
        });
    },
    selectByIds(cartIds) {
        let params = "?cartIds=";
        for (let i = 0; i < cartIds.length; i++) {
            params += cartIds[i];
            if (i != cartIds.length - 1) {
                params += "&cartIds=";
            }
        }
        return service.get(`/cart/ids${params}`);
    }

}


export default cartApi;